import java.io.IOException;
import java.io.RandomAccessFile;

public final class CacheIndex {
	private int anInt514;
	private boolean aBoolean515 = false;
	static byte[] aByteArray517 = new byte[520];
	RandomAccessFile aRandomAccessFile518;
	RandomAccessFile aRandomAccessFile519;
	int anInt520;
	int anInt521 = 65000;

	public CacheIndex(int i, int i_0_, RandomAccessFile randomaccessfile,
		RandomAccessFile randomaccessfile_1_) {
		(this).anInt520 = i;
		(this).aRandomAccessFile518 = randomaccessfile;
		(this).aRandomAccessFile519 = randomaccessfile_1_;
		(this).anInt521 = i_0_;
	}

	public synchronized byte[] method292(byte i, int i_3_) {
		try {
			if (i == 6) {
				i = (byte) 0;
			} else {
				aBoolean515 = !aBoolean515;
			}
			try {
				method295(true, i_3_ * 6, (this).aRandomAccessFile519);
				int i_4_;
				for (int i_5_ = 0; i_5_ < 6; i_5_ += i_4_) {
					i_4_ = (this).aRandomAccessFile519.read(CacheIndex.aByteArray517, i_5_, 6 - i_5_);
					if (i_4_ == -1) {
						return null;
					}
				}
				i_4_ = (((CacheIndex.aByteArray517[0] & 0xff) << 16)
					+ ((CacheIndex.aByteArray517[1] & 0xff) << 8) + (CacheIndex.aByteArray517[2] & 0xff));
				int i_6_ = (((CacheIndex.aByteArray517[3] & 0xff) << 16)
					+ ((CacheIndex.aByteArray517[4] & 0xff) << 8) + (CacheIndex.aByteArray517[5] & 0xff));
				if (i_4_ < 0 || i_4_ > (this).anInt521) {
					return null;
				}
				if (i_6_ <= 0 || i_6_ > (this).aRandomAccessFile518.length() / 520L) {
					return null;
				}
				byte[] is = new byte[i_4_];
				int i_7_ = 0;
				int i_8_ = 0;
				while (i_7_ < i_4_) {
					if (i_6_ == 0) {
						return null;
					}
					method295(true, i_6_ * 520, (this).aRandomAccessFile518);
					int i_9_ = 0;
					int i_10_ = i_4_ - i_7_;
					if (i_10_ > 512) {
						i_10_ = 512;
					}
					int i_11_;
					for (/**/; i_9_ < i_10_ + 8; i_9_ += i_11_) {
						i_11_ = (this).aRandomAccessFile518.read(CacheIndex.aByteArray517, i_9_, i_10_
							+ 8 - i_9_);
						if (i_11_ == -1) {
							return null;
						}
					}
					i_11_ = ((CacheIndex.aByteArray517[0] & 0xff) << 8)
						+ (CacheIndex.aByteArray517[1] & 0xff);
					int i_12_ = (((CacheIndex.aByteArray517[2] & 0xff) << 8) + (CacheIndex.aByteArray517[3] & 0xff));
					int i_13_ = (((CacheIndex.aByteArray517[4] & 0xff) << 16)
						+ ((CacheIndex.aByteArray517[5] & 0xff) << 8) + (CacheIndex.aByteArray517[6] & 0xff));
					int i_14_ = CacheIndex.aByteArray517[7] & 0xff;
					if (i_11_ != i_3_ || i_12_ != i_8_ || i_14_ != (this).anInt520) {
						return null;
					}
					if (i_13_ < 0 || i_13_ > (this).aRandomAccessFile518.length() / 520L) {
						return null;
					}
					for (int i_15_ = 0; i_15_ < i_10_; i_15_++) {
						is[i_7_++] = CacheIndex.aByteArray517[i_15_ + 8];
					}
					i_6_ = i_13_;
					i_8_++;
				}
				return is;
			} catch (IOException ioexception) {
				return null;
			}
		} catch (RuntimeException runtimeexception) {
			Signlink.reporterror("38418, " + i + ", " + i_3_ + ", " + runtimeexception.toString());
			throw new RuntimeException();
		}
	}

	public synchronized boolean method293(int i, boolean bool, byte[] is, int i_16_) {
		if (!bool) {
			for (int i_17_ = 1; i_17_ > 0; i_17_++) {
				/* empty */
			}
		}
		boolean bool_18_ = method294(is, anInt514, i_16_, true, i);
		if (!bool_18_) {
			bool_18_ = method294(is, anInt514, i_16_, false, i);
		}
		return bool_18_;
	}

	private synchronized boolean method294(byte[] is, int i, int i_19_, boolean bool, int i_20_) {
		try {
			if (i != 0) {
				throw new NullPointerException();
			}
			try {
				int i_21_;
				if (bool) {
					method295(true, i_19_ * 6, (this).aRandomAccessFile519);
					int i_22_;
					for (int i_23_ = 0; i_23_ < 6; i_23_ += i_22_) {
						i_22_ = (this).aRandomAccessFile519.read(CacheIndex.aByteArray517, i_23_,
							6 - i_23_);
						if (i_22_ == -1) {
							return false;
						}
					}
					i_21_ = (((CacheIndex.aByteArray517[3] & 0xff) << 16)
						+ ((CacheIndex.aByteArray517[4] & 0xff) << 8) + (CacheIndex.aByteArray517[5] & 0xff));
					if (i_21_ <= 0 || i_21_ > (this).aRandomAccessFile518.length() / 520L) {
						return false;
					}
				} else {
					i_21_ = (int) (((this).aRandomAccessFile518.length() + 519L) / 520L);
					if (i_21_ == 0) {
						i_21_ = 1;
					}
				}
				CacheIndex.aByteArray517[0] = (byte) (i_20_ >> 16);
				CacheIndex.aByteArray517[1] = (byte) (i_20_ >> 8);
				CacheIndex.aByteArray517[2] = (byte) i_20_;
				CacheIndex.aByteArray517[3] = (byte) (i_21_ >> 16);
				CacheIndex.aByteArray517[4] = (byte) (i_21_ >> 8);
				CacheIndex.aByteArray517[5] = (byte) i_21_;
				method295(true, i_19_ * 6, (this).aRandomAccessFile519);
				(this).aRandomAccessFile519.write(CacheIndex.aByteArray517, 0, 6);
				int i_24_ = 0;
				int i_25_ = 0;
				while (i_24_ < i_20_) {
					int i_26_ = 0;
					if (bool) {
						method295(true, i_21_ * 520, (this).aRandomAccessFile518);
						int i_27_;
						int i_28_;
						for (i_28_ = 0; i_28_ < 8; i_28_ += i_27_) {
							i_27_ = (this).aRandomAccessFile518.read(CacheIndex.aByteArray517, i_28_,
								8 - i_28_);
							if (i_27_ == -1) {
								break;
							}
						}
						if (i_28_ == 8) {
							i_27_ = (((CacheIndex.aByteArray517[0] & 0xff) << 8) + (CacheIndex.aByteArray517[1] & 0xff));
							int i_29_ = (((CacheIndex.aByteArray517[2] & 0xff) << 8) + (CacheIndex.aByteArray517[3] & 0xff));
							i_26_ = (((CacheIndex.aByteArray517[4] & 0xff) << 16)
								+ ((CacheIndex.aByteArray517[5] & 0xff) << 8) + (CacheIndex.aByteArray517[6] & 0xff));
							int i_30_ = CacheIndex.aByteArray517[7] & 0xff;
							if (i_27_ != i_19_ || i_29_ != i_25_ || i_30_ != (this).anInt520) {
								return false;
							}
							if (i_26_ < 0 || i_26_ > (this).aRandomAccessFile518.length() / 520L) {
								return false;
							}
						}
					}
					if (i_26_ == 0) {
						bool = false;
						i_26_ = (int) (((this).aRandomAccessFile518.length() + 519L) / 520L);
						if (i_26_ == 0) {
							i_26_++;
						}
						if (i_26_ == i_21_) {
							i_26_++;
						}
					}
					if (i_20_ - i_24_ <= 512) {
						i_26_ = 0;
					}
					CacheIndex.aByteArray517[0] = (byte) (i_19_ >> 8);
					CacheIndex.aByteArray517[1] = (byte) i_19_;
					CacheIndex.aByteArray517[2] = (byte) (i_25_ >> 8);
					CacheIndex.aByteArray517[3] = (byte) i_25_;
					CacheIndex.aByteArray517[4] = (byte) (i_26_ >> 16);
					CacheIndex.aByteArray517[5] = (byte) (i_26_ >> 8);
					CacheIndex.aByteArray517[6] = (byte) i_26_;
					CacheIndex.aByteArray517[7] = (byte) (this).anInt520;
					method295(true, i_21_ * 520, (this).aRandomAccessFile518);
					(this).aRandomAccessFile518.write(CacheIndex.aByteArray517, 0, 8);
					int i_31_ = i_20_ - i_24_;
					if (i_31_ > 512) {
						i_31_ = 512;
					}
					(this).aRandomAccessFile518.write(is, i_24_, i_31_);
					i_24_ += i_31_;
					i_21_ = i_26_;
					i_25_++;
				}
				return true;
			} catch (IOException ioexception) {
				return false;
			}
		} catch (RuntimeException runtimeexception) {
			Signlink.reporterror("23479, " + is + ", " + i + ", " + i_19_ + ", " + bool + ", "
				+ i_20_ + ", " + runtimeexception.toString());
			throw new RuntimeException();
		}
	}

	public synchronized void method295(boolean bool, int i, RandomAccessFile randomaccessfile)
		throws IOException {
		if (bool) {
			if (i < 0 || i > 62914560) {
				System.out.println("Badseek - pos:" + i + " len:" + randomaccessfile.length());
				i = 62914560;
				try {
					Thread.sleep(1000L);
				} catch (Exception exception) {
					/* empty */
				}
			}
			randomaccessfile.seek(i);
		}
	}
}
